home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / ICAppSourceKit1.0 / ICGlobals.p < prev    next >
Encoding:
Text File  |  1994-11-27  |  3.7 KB  |  137 lines  |  [TEXT/PJMM]

  1. unit ICGlobals;
  2.  
  3. interface
  4.  
  5.     const
  6.         M_File = 129;
  7.         M_Edit = 130;
  8.         M_Install = 131;
  9.         M_Windows = 132;
  10.  
  11.     const
  12.         EM_Undo = 1;
  13.         (* *)
  14.         EM_Cut = 3;
  15.         EM_Copy = 4;
  16.         EM_Paste = 5;
  17.         EM_Clear = 6;
  18.         EM_SelectAll = 7;
  19.  
  20.     const
  21.         FM_New = 1;
  22.         FM_Open = 2;
  23.         FM_OpenInternetPreferences = 3;
  24.         (* *)
  25.         FM_Close = 5;
  26.         FM_Save = 6;
  27.         FM_SaveAs = 7;
  28.         (* *)
  29.         FM_Quit = 9;
  30.  
  31.     const
  32.         IM_Install = 1;
  33.         IM_Save = 2;
  34.         IM_Remove = 3;
  35.  
  36.     const                                    { Other OS constants, probably declared somewhere now }
  37.         kSysEnvironsVersion = 1;
  38.         kOSEvent = app4Evt;                {event used by MultiFinder}
  39.         kSuspendResumeMessage = 1;    {high byte of suspend/resume event message}
  40.         kResumeMask = 1;                    {bit of message field for resume vs. suspend}
  41.         kMouseMovedMessage = $FA;    {high byte of mouse-moved event message}
  42.         kNoEvents = 0;                        {no events mask}
  43.  
  44.     var  { set up by InitSystemGlobals }
  45.         system7: boolean;
  46.         has_appleEvents: boolean;
  47.         has_findfolder: boolean;
  48.         has_aliasMgr: boolean;
  49.         has_newStdFile: boolean;
  50.         has_HelpMgr: boolean;
  51.         has_colorQD: boolean;
  52.         has_components: boolean;
  53.         app_resfile: integer;
  54.         app_fs: FSSpec;
  55.         in_foreground: boolean;
  56.         quitNow: boolean;
  57.         app_version: VersRec;
  58.  
  59.     procedure InitGlobals;
  60.  
  61.     function InForeground: boolean;
  62.  
  63.     type
  64.         icAction = (acDoThis, acInstallComponent, acOpenWindow, acNewDocument, acOpenDocument, acCloseWindow, acSave, {}
  65.             acQuit, acStartApplication, acGetExample, acChooseApplication, acRemoveComponent);
  66.  
  67.     procedure DisplayError (action: icAction; err: OSErr);
  68.  
  69. implementation
  70.  
  71.     uses
  72.         Processes, Components;
  73.  
  74.     procedure InitGlobals;
  75.         var
  76.             oe: OSErr;
  77.             gv: longInt;
  78.             pb: FCBPBRec;
  79.             sysenv: sysEnvRec;
  80.             versh: VersRecHndl;
  81.     begin
  82.         app_resfile := CurResFile;
  83.         pb.ioNamePtr := @app_fs.name;
  84.         pb.ioVRefNum := 0;
  85.         pb.ioRefNum := app_resfile;
  86.         pb.ioFCBIndx := 0;
  87.         oe := PBGetFCBInfo(@pb, false);
  88.         app_fs.vRefNum := pb.ioFCBVRefNum;
  89.         app_fs.parID := pb.ioFCBParID;
  90.         has_colorqd := (SysEnvirons(1, sysEnv) = noErr) & sysenv.hasColorQD; { Gestalt has a bug that causes hasColourQD to always be set }
  91.         system7 := (Gestalt(gestaltSystemVersion, gv) = noErr) & (gv >= $0700);
  92.         has_AppleEvents := (Gestalt(gestaltAppleEventsAttr, gv) = noErr) & (BTST(gv, gestaltAppleEventsPresent));
  93.         has_findfolder := (Gestalt(gestaltFindFolderAttr, gv) = noErr) & (BTST(gv, gestaltFindFolderPresent));
  94.         has_newStdFile := (Gestalt(gestaltStandardFileAttr, gv) = noErr) & (BTST(gv, gestaltStandardFile58));
  95.         has_HelpMgr := (Gestalt(gestaltHelpMgrAttr, gv) = noErr) & (BTST(gv, gestaltHelpMgrPresent));
  96.         has_aliasMgr := (Gestalt(gestaltAliasMgrAttr, gv) = noErr) & (BTST(gv, gestaltAliasMgrPresent));
  97.         has_components := (Gestalt(gestaltComponentMgr, gv) = noErr) & (gv > 0);
  98.         versh := VersRecHndl(Get1Resource('vers', 1));
  99.         if versh <> nil then begin
  100.             app_version := versh^^;
  101.         end
  102.         else begin
  103.             app_version.numericVersion.version := 0;
  104.             app_version.countryCode := 0;
  105.             app_version.shortVersion := '';
  106.         end; (* if *)
  107.     end;
  108.  
  109.     function InForeground: boolean;
  110.         var
  111.             gv: longInt;
  112.             ourpsn, frontpsn: ProcessSerialNumber;
  113.             front: boolean;
  114.     begin
  115.         if (Gestalt(gestaltOSAttr, gv) = noErr) & (BTST(gv, gestaltLaunchControl)) then begin
  116.             if (GetCurrentProcess(ourpsn) = noErr) & (GetFrontProcess(frontpsn) = noErr) then begin
  117.                 if SameProcess(ourpsn, frontpsn, front) = noErr then
  118.                     in_foreground := front;
  119.             end;
  120.         end;
  121.         InForeground := in_foreground;
  122.     end;
  123.  
  124.     procedure DisplayError (action: icAction; err: OSErr);
  125.         var
  126.             junk: integer;
  127.             tmp: Str255;
  128.     begin
  129.         if (err <> noErr) and (err <> userCanceledErr) then begin
  130.             InitCursor;
  131.             GetIndString(tmp, 131, ord(action) + 1);
  132.             ParamText(tmp, StringOf(err : 1), '', '');
  133.             junk := StopAlert(140, nil);
  134.         end; (* if *)
  135.     end; (* DisplayError *)
  136.  
  137. end. (* ICGlobals *)